package se.webbzon.boltzmann.editor.component.imagelist;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JList;
import javax.swing.ListCellRenderer;

import se.webbzon.boltzmann.editor.list.EditorListCell;

public class ImageSetListCell extends EditorListCell implements ListCellRenderer<ImageSetEntry> {
	
	// Auto generated serial version UID
	private static final long serialVersionUID = 2862435137243610204L;
	
	// The image entry associated with this list cell
	private ImageSetEntry entry;

	/*============================================================
	Constructors
	============================================================*/

	public ImageSetListCell(Dimension d) {
		super(d);
	}

	/*============================================================
	Public Methods
	============================================================*/

	@Override public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setFont(getFont());
		if (entry == null) {
			g.drawString("No image (null)", 8, 32);
		} else {
			g.drawImage(entry.getImageSet().get(0), 0, 0, 64, 64, this);
			g.drawString(entry.getImageSetName(), 80, 32);
		}
	}

	@Override public Component getListCellRendererComponent(
			JList<? extends ImageSetEntry> list, ImageSetEntry entry, int index,
			boolean isSelected, boolean cellHasFocus) {
		setSelected(isSelected);
		this.entry = entry;
		return this;
	}

}
